package com.beadhouse.base.support.service;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beadhouse.base.dao.UserDao;
import com.beadhouse.base.service.UserService;
import com.beadhouse.common.exeption.BeadHouseException;
import com.beadhouse.entity.UserEntity;
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	UserDao udao;
	@Override
	public UserEntity login(String account, String password) throws Exception {
		//1验证清理参数
		
				if(account==null||(account=account.trim()).length()==0) {
					throw new BeadHouseException("账号不能为空");
				}
				
				if(password==null||(password=password.trim()).length()==0) {
					throw new BeadHouseException("密码不能为空");
				}
				if(account.length()>32) {
					throw new BeadHouseException("账号不存在");
				}
				
				//2执行业务逻辑
				//2.1账号是否存在
				UserEntity u=udao.select("account",account);
				if(u==null) {
					throw new BeadHouseException("账号和密码不匹配");
				}
				
				//2.2密码是否正确
				
					if(!u.getPassword().equals(password)) {
						throw new BeadHouseException("账号和密码不匹配");
					}	
				
				//2.3判断账号是否锁定
				
				//2.4更新登录ip和登录时间
				return u;
	}

}
